package com.mall.server.service.sms;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.dubbo.api.SmsHomeAdvertiseApi;
import com.mall.model.domain.SmsHomeAdvertise;
import com.mall.model.vo.CommonPage;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsHomeAdvertiseService {

    @DubboReference
    private SmsHomeAdvertiseApi smsHomeAdvertiseApi;

    //分页查询广告
    public CommonPage list(Integer pageNum, Integer pageSize, String name, String endTime, Integer type) {

        Page<SmsHomeAdvertise> page = smsHomeAdvertiseApi.listPage(pageNum, pageSize, name, type, endTime);
        return new CommonPage(page);
    }

    //添加
    public void create(SmsHomeAdvertise advertise) {

        advertise.setClickCount(0);
        advertise.setOrderCount(0);

        smsHomeAdvertiseApi.save(advertise);
    }

    public void delete(List<Long> ids) {

        smsHomeAdvertiseApi.removeByIds(ids);
    }

    //修改
    public void update(Integer id, SmsHomeAdvertise advertise) {

        smsHomeAdvertiseApi.updateByAdvertise(id, advertise);

    }

    //获取广告详情
    public SmsHomeAdvertise findById(Integer id) {

        return smsHomeAdvertiseApi.getById(id);

    }

}
